// pages/order/order.js
const app = getApp()
var api = require('../../../utils/api.js')
var util = require('../../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
     page: 1,
     limit: 10,
     total_page: 0,
  },

  onLoad: function(options) {
    var that = this;
  },

  onShow:function(){
    var that=this;
     this.setData({
        page: 1
     })
     wx.showLoading({
        title: '加载中',
        mask: true
     })
     this.getOrderLIst();
  },
   // 获取订单列表
   getOrderLIst: function () {
      var params = new Object()
      var that = this;
      // params.page = this.data.page;
      // params.limit = this.data.limit;

      api.POST({
         params: params,
         url: app.globalData.base_url + 'inn/getOrderList',
         success: function (res) {
            wx.hideLoading();
            if (util.isEmpty(res.data.code)) {
               // var paging = res.data.data.paging;
               // var totalPage = paging.total_page;
               var itemData = res.data.data.order_list;

               // if (that.data.page == 1) {
               //    var itemData = orderList;
               // } else {
               //    var itemData = that.data.product.concat(orderList)
               // }

               that.setData({
                  // total_page: totalPage,
                  product: itemData
               })
            }
         },
         fail: function (fail) {
            util.showError("网络错误，请检查网络");
         }
      })
   },

   //加载更多
   loadMore: function () {
      if (this.data.page >= this.data.total_page) {
         return;
      }
      wx.showLoading({
         title: '加载中',
         mask:true
      })
      this.setData({
         page: this.data.page + 1
      });
      this.getOrderLIst();
   },

   //刷新页面
   resetData: function () {
      var that = this
      that.setData({
         page: 1,
         hasMore: true
      });
      this.getOrderLIst();
   },
   //页面下拉刷新
   onPullDownRefresh: function () {
      var that = this;

      setTimeout(function () {
         that.resetData()
      }, 1000)
      wx.stopPullDownRefresh();
   },

   //页面上拉触底
   onReachBottom: function (e) {
      this.loadMore();
   },

   callPhone:function(e){
      var phone = e.currentTarget.dataset.phone;
      wx.makePhoneCall({
         phoneNumber: phone
      })
   }


})